#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

void solve() {
  int n, k;
  cin >> n >> k;
  using pii = pair<i64, int>;
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  int cur = 0;
  i64 time = 0;
  for (int i = 0; i < n; i ++) {
    int a, b, c;
    cin >> a >> b >> c;
    while (cur + c > k) {
      auto [t, x] = pq.top();
      pq.pop();
      time = t;
      cur -= x;
    }
    i64 ans = max(time, (i64)a);
    cout << ans << '\n';
    pq.emplace(ans + b, c);
    cur += c;
  }
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int T = 1;
  // cin >> T;
  for (int cas = 1; cas <= T; cas ++) {
    // cout << "Case #" << cas << ": ";
    solve();
  }
}